23 template <class T
> string
toStr(const T
&x
) { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
) { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
28 #define D(x) cout << #x " = " << (x) << endl
30 const double EPS
= 1e-10;
32 int cmp(double x
, double y
= 0, double tol
= EPS
){
33 return( x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
38 point(){} point(double x
, double y
, double z
) : x(x
), y(y
), z(z
) {}
45 inline double dist(const point
&a
, const point
&b
) {
46 double dx
= b
.x
- a
.x
, dy
= b
.y
- a
.y
, dz
= b
.z
- a
.z
;
47 return sqrt(dx
* dx
+ dy
* dy
+ dz
* dz
);
50 bool lessThan(double a
, double b
) {
54 point
positionAt(int p
, double t
) {
57 int i
= upper_bound(D
[p
], D
[p
] + P
[p
].size(), d
) - D
[p
] - 1;
60 double distance
= dist(P
[p
][i
], P
[p
][i
+1]);
61 assert(cmp(s
+ distance
, d
) >= 0);
63 if (cmp(distance
, 0.0) > 0) {
64 double dx
= P
[p
][i
+1].x
- P
[p
][i
].x
;
65 double dy
= P
[p
][i
+1].y
- P
[p
][i
].y
;
66 double dz
= P
[p
][i
+1].z
- P
[p
][i
].z
;
67 ans
.x
+= (d
- s
) * dx
/ distance
;
68 ans
.y
+= (d
- s
) * dy
/ distance
;
69 ans
.z
+= (d
- s
) * dz
/ distance
;
71 assert(cmp(s
+ dist(P
[p
][i
], ans
), d
) == 0);
76 int casos
; scanf("%d", &casos
); while (casos
--) {
77 for (int p
= 0; p
< 2; ++p
) {
78 int k
; scanf("%d %d %d", &R
[p
], &V
[p
], &k
);
80 for (int i
= 0; i
< k
; ++i
) {
81 scanf("%lf %lf %lf", &P
[p
][i
].x
, &P
[p
][i
].y
, &P
[p
][i
].z
);
83 P
[p
].push_back( point(0, 0, 0) );
86 double totalTime
= 1e100
;
87 for (int p
= 0; p
< 2; ++p
) {
89 for (int i
= 1; i
< P
[p
].size(); ++i
) {
90 D
[p
][i
] = D
[p
][i
-1] + dist(P
[p
][i
-1], P
[p
][i
]);
92 totalTime
= min(totalTime
, D
[p
][P
[p
].size() - 1] / V
[p
]);
95 int iterations
= 40000;
96 double delta
= totalTime
/ iterations
;
97 // point p1 = positionAt(0, totalTime);
98 // point p2 = positionAt(1, totalTime);
99 // printf("<%lf, %lf, %lf>\n", p1.x, p1.y, p1.z);
100 // printf("<%lf, %lf, %lf>\n", p2.x, p2.y, p2.z);
103 for (int i
= 0; i
<= iterations
; ++i
) {
104 double distance
= dist(positionAt(0, i
* delta
), positionAt(1, i
* delta
));
105 if (cmp(distance
, 1.0 * (R
[0] + R
[1])) <= 0) {